<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@ include file="/WEB-INF/jsp/common/tags.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户管理</title>
<%@ include file="/WEB-INF/jsp/common/ui.jsp"%>
</head>
<body style="visibility: visible;" >
	<div id="tb" style="padding: 5px; height: auto">
		<shiro:hasPermission name="/user/add">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-add" plain="true" id="addbtn">新增</a>
		</shiro:hasPermission>
		&nbsp; &nbsp;
		<shiro:hasPermission name="/user/edit">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-edit" plain="true" id="editbtn">修改</a>
		</shiro:hasPermission>
		&nbsp; &nbsp;
		<shiro:hasPermission name="/user/delete">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-remove" plain="true" id="delbtn">停用</a>
		</shiro:hasPermission>
		&nbsp; &nbsp;
		<shiro:hasPermission name="/aps.do">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-add" plain="true" id="addrolebtn">分配角色</a>
		</shiro:hasPermission>
		<shiro:hasPermission name="/udAllocation.do">
			<a href="javascript:void(0)" class="easyui-linkbutton"
				iconCls="icon-add" plain="true" id="adddeptbtn">分配部门</a>
		</shiro:hasPermission>
		<form:form action="" method="post" id="searchForm">
       		用户账号:   
        	<input class="easyui-validatebox" type="text" id="account" name="account" data-options="">
        	<a href="javascript:void(0)" class="easyui-linkbutton" id="submit_search" iconCls="icon-search" ">Search</a> 
        </form:form>
	</div>


	<table id="tt" class="easyui-datagrid"
		style="width: auto; height: 320px"
		data-options="fit:true,collapsible:true,rownumbers:true,url:'<%=path%>/user/list',fitColumns:false,singleSelect:false,sortOrder:'desc',sortName:'clintname',pagination:true,toolbar:'#tb'"
		title="数据加载列表" iconCls="icon-save">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
				<th data-options="field:'id'">编号</th>
				<th data-options="field:'name'">姓名</th>
				<th data-options="field:'account'">帐号</th>
				<th data-options="field:'email'">邮箱</th>
				<th align="center" data-options="field:'updateTime'">更新时间</th>
				<th align="center" data-options="field:'createTime'">创建时间</th>
			</tr>
		</thead>
	</table>
</body>

<script type="text/javascript">
    function addPanel(url,title){
	    var tab=parent.$('#tabs').tabs('exists',title);
			if(tab){
				//若存在，则直接打开
				parent.$('#tabs').tabs('select',title);
			}else{
				 parent.$('#tabs').tabs('add',{
	                title: title,
	                content: "<iframe width='100%' height='100%'  id='iframe' frameborder='0' scrolling='auto'  src='<%=path%>"+url+"'></iframe>",
	                closable: true
	            });
				
			}
           
       }
       
       //title 标题_编号
      function editPanel(url,title){
	     parent.$('#tabs').tabs('add',{
	                title: title,
	                content: "<iframe width='100%' height='100%'  id='iframe' frameborder='0' scrolling='auto'  src='<%=path%>"+ url + "'></iframe>",
							closable : true
						});

	}

	//post提交批量删除信息并弹出处理结果
	function delDatas(delList, listId, address) {
		var mes = "确定要删除选中行吗";	
		
		$.messager.confirm('提示信息', mes, function(b) {
			if (b) {
				$.ajax({
					url : address,
					type : 'POST',
					data : {
						ids : delList
					},
					dataType : 'json',
					timeout : 15000,
					error : function() {
						alert('Error ');
					},
					success : function(result) {
						$.messager.alert('信息提示', result.resultMsg, 'info');
						$(listId).datagrid('reload');

					}

				});

			}
		});
	}

	var toolbar = [ {
		text : '新增',
		iconCls : 'icon-add',
		handler : function() {

		}
	}, {
		text : '修改',
		iconCls : 'icon-edit',
		handler : function() {

		}
	}, '-', {
		text : '删除',
		iconCls : 'icon-remove',
		handler : function() {

		}
	} ];


	$(function() {

		$("#submit_search").click(function() {
			var f = $('#searchForm').form('validate');
			if (f) {
				$('#tt').datagrid('load', {
					"account" : $('#account').val()
				});
			} else {

				return f;
			}

		});

		//$('#tt').datagrid('reload',{pageindex:11});
		$("#addbtn").click(function() {
			addPanel('/user/add', '新增用户');
		});

		$("#editbtn").click(
				function() {
					var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
					var parks = [];
					if (rows == 0) {
						$.messager.alert("系统提示", "请选择要修改的数据!", "info");
						return;
					} else if (rows.length > 1) {
						$.messager.alert("系统提示", "一次只能修改一条数据!", "info");
						return;

					} else {
						for (var i = 0; i < rows.length; i++) {
							parks.push(rows[i].id);
						}
						var parkparams = parks.join(',');

						editPanel('/user/edit?id=' + parkparams, '修改用户密码_' + parkparams);

					}
				});

		$("#addrolebtn").click(function() {
			var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
			var parks = [];
			if (rows == 0) {
				$.messager.alert("系统提示", "请选择要分配的数据!", "info");
				return;
			} else if (rows.length > 1) {
				$.messager.alert("系统提示", "一次只能分配一条数据!", "info");
				return;

			} else {
				for (var i = 0; i < rows.length; i++) {
					parks.push(rows[i].id);
				}
				var parkparams = parks.join(',');

				editPanel('aps.do?id=' + parkparams, '分配用户角色_' + parkparams);

			}
		});

		$("#adddeptbtn").click(
				function() {
					var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
					var parks = [];
					if (rows == 0) {
						$.messager.alert("系统提示", "请选择要分配的数据!", "info");
						return;
					} else if (rows.length > 1) {
						$.messager.alert("系统提示", "一次只能分配一条数据!", "info");
						return;

					} else {
						for (var i = 0; i < rows.length; i++) {
							parks.push(rows[i].id);
						}
						var parkparams = parks.join(',');

						editPanel('udAllocation.do?id=' + parkparams, '分配用户部门_'
								+ parkparams);

					}
				});

		$("#delbtn").click(function() {
			var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
			var parks = [];
			if (rows == 0) {
				$.messager.alert("系统提示", "请选择要删除的数据!", "info");
				return;

			} else {
				for (var i = 0; i < rows.length; i++) {
					parks.push(rows[i].id);
				}
				var parkparams = parks.join(',');
				delDatas(parkparams, '#tt', 'deleteUser.do');
			}
		});

		

		$("#smsbtn").click(function() {
			var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
			var parks = [];
			if (rows == 0) {
				$.messager.alert("系统提示", "请选择要接受的用户!", "info");
				return;

			} else {
				for (var i = 0; i < rows.length; i++) {
					parks.push(rows[i].id);
				}
				var parkparams = parks.join(',');
				delDatas(parkparams, '#tt', 'setAcceptUser.do');
			}
		});

		$("#smsDkbtn").click(function() {
			var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
			var parks = [];
			if (rows == 0) {
				$.messager.alert("系统提示", "请选择要接受的用户!", "info");
				return;

			} else {
				for (var i = 0; i < rows.length; i++) {
					parks.push(rows[i].id);
				}
				var parkparams = parks.join(',');
				delDatas(parkparams, '#tt', 'setAcceptDkUser.do');
			}
		});

		$("#smsCancelDkbtn").click(function() {
			var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
			var parks = [];
			if (rows == 0) {
				$.messager.alert("系统提示", "请选择要取消的用户!", "info");
				return;

			} else {
				for (var i = 0; i < rows.length; i++) {
					parks.push(rows[i].id);
				}
				var parkparams = parks.join(',');
				delDatas(parkparams, '#tt', 'CancelAcceptUserDk.do');
			}
		});

		$("#smsCkbtn").click(function() {
			var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
			var parks = [];
			if (rows == 0) {
				$.messager.alert("系统提示", "请选择要接受的用户!", "info");
				return;

			} else {
				for (var i = 0; i < rows.length; i++) {
					parks.push(rows[i].id);
				}
				var parkparams = parks.join(',');
				delDatas(parkparams, '#tt', 'setAcceptCkUser.do');
			}
		});

		$("#smsCancelCkbtn").click(function() {
			var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
			var parks = [];
			if (rows == 0) {
				$.messager.alert("系统提示", "请选择要取消的用户!", "info");
				return;

			} else {
				for (var i = 0; i < rows.length; i++) {
					parks.push(rows[i].id);
				}
				var parkparams = parks.join(',');
				delDatas(parkparams, '#tt', 'CancelAcceptUserCk.do');
			}
		});

		$("#cancelbtn").click(function() {
			var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
			var parks = [];
			if (rows == 0) {
				$.messager.alert("系统提示", "请选择要接受的用户!", "info");
				return;

			} else {
				for (var i = 0; i < rows.length; i++) {
					parks.push(rows[i].id);
				}
				var parkparams = parks.join(',');
				delDatas(parkparams, '#tt', 'CancelAcceptUser.do');
			}
		});

		$("#addcompanybtn").click(
				function() {
					var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
					var parks = [];
					if (rows == 0) {
						$.messager.alert("系统提示", "请选择要分配的数据!", "info");
						return;
					} else if (rows.length > 1) {
						$.messager.alert("系统提示", "一次只能分配一条数据!", "info");
						return;

					} else {
						for (var i = 0; i < rows.length; i++) {
							parks.push(rows[i].id);
						}
						var parkparams = parks.join(',');

						editPanel('distributionCompany.do?id=' + parkparams,
								'分配用户公司_' + parkparams);

					}
				});

		$("#addContactsbtn").click(
				function() {
					var rows = $("#tt").datagrid("getSelections"); // 获取所有选中的行
					var parks = [];
					if (rows == 0) {
						$.messager.alert("系统提示", "请选择要分配的数据!", "info");
						return;
					} else if (rows.length > 1) {
						$.messager.alert("系统提示", "一次只能分配一条数据!", "info");
						return;

					} else {
						for (var i = 0; i < rows.length; i++) {
							parks.push(rows[i].id);
						}
						var parkparams = parks.join(',');

						editPanel('saveUserContactsRelation.do?id='
								+ parkparams, '分配用户联系人_' + parkparams);

					}
				});

	});
</script>
</html>